<?php
/**
 * Created by JetBrains PhpStorm.
 * User: romanches
 * Date: 25.08.11
 * Time: 12:52
 * To change this template use File | Settings | File Templates.
 */

class ThumbUtil{

	//location of images file, example '/img'
	const IMAGES_LOCATION = '/images';

	public static function getImagesLocationRoot(){
		return $_SERVER['DOCUMENT_ROOT'] .ThumbUtil::IMAGES_LOCATION;
	}

    public static function createSmallThumb($inputFilePath, $outputFilePath, $outputFileName){
            include_once('easyphpthumbnail.class.php');
            $thumb = new easyphpthumbnail;
            $thumb->Thumbsize = 130;
            $thumb -> Cropimage = array(3,0,0,0,0,0);
//            $thumb -> Shadow = true;
//            $thumb -> Clipcorner = array(2,4,0,1,1,1,1);
            $thumb -> Thumblocation = ThumbUtil::getImagesLocationRoot().$outputFilePath.'/';
            $thumb->Thumbfilename = $outputFileName;
            $thumb->Createthumb(ThumbUtil::getImagesLocationRoot().$inputFilePath, "file");
    }

        public static function createPreview($inputFilePath, $outputFilePath, $outputFileName){
            include_once('easyphpthumbnail.class.php');
            $thumb = new easyphpthumbnail;
            $thumb->Thumbwidth = 300;
//            $thumb->Thumbheight = 200;
            $thumb -> Cropimage = array(3,0,0,0,0,0);
            $thumb -> Clipcorner = array(2,15,0,1,1,1,1);
            $thumb -> Thumblocation = ThumbUtil::getImagesLocationRoot().$outputFilePath.'/';
            $thumb->Thumbfilename = $outputFileName;
            $thumb->Createthumb(ThumbUtil::getImagesLocationRoot().$inputFilePath, "file");
        }

        public static function deleteThumbByShortPath($path){
            $path = $_SERVER['DOCUMENT_ROOT'].$path;
            if (@fopen($path, "r"))
            unlink ($path);
        }

        public static function deleteThumbByFullPath($path){
            if (@fopen($path, "r"))
            unlink ($path);
        }
    }

